package edu.gatech.cc.CFAWaffleFriesWheresMyStuff.common;

import android.content.Context;
import android.database.SQLException;

/**
 * Factory class for Datastore. Every time a datastore is needed, this class's static method is called to get it,
 * and when we want to switch to a different type of data storage, all that needs to be changed is this class.
 * @author Michael Luke Hawkins
 */
public class DatastoreFactory {
	
	private static Datastore _instance;
	
	public static Datastore getDatastore(Context context)
	{
		if(_instance == null)
		{
			WMSDatabase database = new WMSDatabase(context);
			 try 
			 {
				 database.createDatabase();  
			 }
			 catch (Exception e) 
			 {
				 throw new Error("Unable to create database");
			 }
				  
			try 
			{
				database.openDatabase();
			}
			catch(SQLException sqle)
			{
				 throw sqle;
			}
			_instance = database;
		}
		return _instance;
	}
	
}
